home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Framewrk / FWPart / Sources / FWLnkCmd.cpp < prev    next >
Encoding:
Text File  |  1996-08-16  |  7.9 KB  |  245 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWLnkCmd.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWFrameW.hpp"
  11.  
  12. #ifndef FWLNKCMD_H
  13. #include "FWLnkCmd.h"
  14. #endif
  15.  
  16. #ifndef FWLNKMGR_H
  17. #include "FWLnkMgr.h"
  18. #endif
  19.  
  20. #ifndef FWLNKDST_H
  21. #include "FWLnkDst.h"
  22. #endif
  23.  
  24. #ifndef FWLNKSRC_H
  25. #include "FWLnkSrc.h"
  26. #endif
  27.  
  28. #ifndef FWPART_H
  29. #include "FWPart.h"
  30. #endif
  31.  
  32. // ----- OS Layer -----
  33.  
  34. #ifndef SLODFSTR_K
  35. #include "SLODFStr.k"
  36. #endif
  37.  
  38. #ifndef SLODFSTR_H
  39. #include "SLODFStr.h"
  40. #endif
  41.  
  42. #ifndef FWMENU_K
  43. #include "FWMenu.k"
  44. #endif
  45.  
  46. // ----- OpenDoc Includes -----
  47.  
  48. #ifndef SOM_Module_OpenDoc_StdTypes_defined
  49. #include <StdTypes.xh>
  50. #endif
  51.  
  52. #ifndef SOM_ODSession_xh
  53. #include <ODSessn.xh>
  54. #endif
  55.  
  56. #ifndef SOM_ODDraft_xh
  57. #include <Draft.xh>
  58. #endif
  59.  
  60. #ifndef SOM_ODLinkSource_xh
  61. #include <LinkSrc.xh>
  62. #endif
  63.  
  64. //========================================================================================
  65. //    Runtime Info
  66. //========================================================================================
  67.  
  68. #ifdef FW_BUILD_MAC
  69. #pragma segment odflinking
  70. #endif
  71.  
  72. FW_DEFINE_AUTO(FW_CPrivCreateLinkSourceCommand)
  73. FW_DEFINE_AUTO(FW_CPrivCreateLinkCommand)
  74.  
  75. //========================================================================================
  76. // FW_CPrivCreateLinkSourceCommand class
  77. //========================================================================================
  78.  
  79. //----------------------------------------------------------------------------------------
  80. // FW_CPrivCreateLinkSourceCommand constructor
  81. //----------------------------------------------------------------------------------------
  82. FW_CPrivCreateLinkSourceCommand::FW_CPrivCreateLinkSourceCommand(Environment* ev,
  83.                                              FW_CFrame* frame,
  84.                                              FW_CLinkManager* linkMgr,
  85.                                              FW_CLinkSource* pendingLink) 
  86. :    FW_CCommand(ev, FW_kCreateLinkSourceCommand, frame, FW_kCanUndo),
  87.     fLinkMgr(linkMgr),
  88.     fLinkSource(pendingLink)
  89. {
  90.     // This command's Undo strings don't matter, because this transaction is always 
  91.     // bracketted by kODBegin/EndAction transactions.
  92. //    this->SetMenuStrings(ev, "", "");
  93.  
  94.     // [MEB] temporary fix for empty Edit menu problem
  95.     SetMenuStrings(ev, "Undo Link Creation", "Redo Link Creation");
  96.  
  97.     FW_END_CONSTRUCTOR
  98. }
  99.  
  100. //----------------------------------------------------------------------------------------
  101. // FW_CPrivCreateLinkSourceCommand destructor
  102. //----------------------------------------------------------------------------------------
  103. FW_CPrivCreateLinkSourceCommand::~FW_CPrivCreateLinkSourceCommand()
  104. {
  105.     FW_START_DESTRUCTOR
  106. }
  107.  
  108. //----------------------------------------------------------------------------------------
  109. // FW_CPrivCreateLinkSourceCommand::CommitUndone
  110. //----------------------------------------------------------------------------------------
  111. void FW_CPrivCreateLinkSourceCommand::CommitUndone(Environment*)
  112. {
  113.     delete fLinkSource;
  114.     fLinkSource = NULL;
  115. }
  116.  
  117. //----------------------------------------------------------------------------------------
  118. // FW_CPrivCreateLinkSourceCommand::DoIt
  119. //----------------------------------------------------------------------------------------
  120. void FW_CPrivCreateLinkSourceCommand::DoIt(Environment* ev)
  121. {
  122.     FW_CPart* part = GetPart(ev);
  123.     ODLinkSource* odLinkSource = part->GetDraft(ev)->CreateLinkSource(ev, part->GetODPart(ev));
  124.     fLinkSource->SetODLinkSource(ev, odLinkSource);
  125.  
  126.     //--- Establish the link ---
  127.     fLinkMgr->AddToSourceLinkList(ev, fLinkSource);
  128.     fLinkSource->PrivLinkEstablished(ev);
  129. }
  130.  
  131. //----------------------------------------------------------------------------------------
  132. // FW_CPrivCreateLinkSourceCommand::GetODLinkSource
  133. //----------------------------------------------------------------------------------------
  134. ODLinkSource* FW_CPrivCreateLinkSourceCommand::GetODLinkSource(Environment* ev)
  135. {
  136.     if (fLinkSource)
  137.         return fLinkSource->GetODLinkSource(ev);
  138.     return NULL;
  139. }
  140.  
  141. //----------------------------------------------------------------------------------------
  142. // FW_CPrivCreateLinkSourceCommand::UndoIt
  143. //----------------------------------------------------------------------------------------
  144. void FW_CPrivCreateLinkSourceCommand::UndoIt(Environment* ev)
  145. {
  146.     fLinkMgr->BreakSourceLink(ev, fLinkSource);        // calls RemoveFromSourceLinkList
  147. }
  148.  
  149. //----------------------------------------------------------------------------------------
  150. // FW_CPrivCreateLinkSourceCommand::RedoIt
  151. //----------------------------------------------------------------------------------------
  152. void FW_CPrivCreateLinkSourceCommand::RedoIt(Environment* ev)
  153. {
  154.     //--- Re-establish the link ---
  155.     fLinkMgr->RestoreSourceLink(ev, fLinkSource);    // calls AddToSourceLinkList
  156. }
  157.  
  158. //========================================================================================
  159. // FW_CPrivCreateLinkCommand class
  160. //========================================================================================
  161.  
  162. //----------------------------------------------------------------------------------------
  163. // FW_CPrivCreateLinkCommand constructor
  164. //----------------------------------------------------------------------------------------
  165. FW_CPrivCreateLinkCommand::FW_CPrivCreateLinkCommand(Environment* ev,
  166.                                              FW_CFrame* frame,
  167.                                              FW_CLinkManager* linkMgr,
  168.                                              FW_Boolean fromClipboard) 
  169. :    FW_CCommand(ev, FW_kCreateLinkCommand, frame, FW_kCanUndo),
  170.     fLinkMgr(linkMgr),
  171.     fLink(NULL)
  172. {
  173.     if (fromClipboard)
  174.     {
  175.         SetActionType(ev, kODBeginAction);
  176.         // ODPG says to use kODEndAction, but my PasteAs command adds its Undo action
  177.         // _after_ the link has been created, so I have to reverse the order of transactions
  178.  
  179.         // Set Undo strings to the ones used for the Paste As command
  180.         FW_CString undoString;
  181.         FW_CString redoString;
  182.         ::FW_PrivLoadUndoStrings(ev, FW_kUndoPasteAsMsg, undoString, redoString);
  183.         SetMenuStrings(ev, undoString, redoString);
  184.     }
  185.     else
  186.     {
  187.         // For Drag&Drop use the default action type, kODSingleAction.
  188.         // The Undo strings don't matter, because this transaction will be 
  189.         // bracketted by kODBegin/EndAction transactions.
  190.         this->SetMenuStrings(ev, "", "");
  191.     }
  192.  
  193.     FW_END_CONSTRUCTOR
  194. }
  195.  
  196. //----------------------------------------------------------------------------------------
  197. // FW_CPrivCreateLinkCommand destructor
  198. //----------------------------------------------------------------------------------------
  199. FW_CPrivCreateLinkCommand::~FW_CPrivCreateLinkCommand()
  200. {
  201.     FW_START_DESTRUCTOR
  202. }
  203.  
  204. //----------------------------------------------------------------------------------------
  205. // FW_CPrivCreateLinkCommand::CommitUndone
  206. //----------------------------------------------------------------------------------------
  207. void FW_CPrivCreateLinkCommand::CommitUndone(Environment*)
  208. {
  209.     // The link creation was Undone
  210.     delete fLink;
  211.     fLink = NULL;
  212. }
  213.  
  214. //----------------------------------------------------------------------------------------
  215. // FW_CPrivCreateLinkCommand::DoIt
  216. //----------------------------------------------------------------------------------------
  217. void FW_CPrivCreateLinkCommand::DoIt(Environment* ev)
  218. {
  219. FW_UNUSED(ev);
  220.     // The main purpose of this command is to add a transaction to the Undo history
  221.     FW_ASSERT(GetCanUndo(ev));
  222.     // Nothing else to do
  223. }
  224.  
  225. //----------------------------------------------------------------------------------------
  226. // FW_CPrivCreateLinkCommand::UndoIt
  227. //----------------------------------------------------------------------------------------
  228. void FW_CPrivCreateLinkCommand::UndoIt(Environment* ev)
  229. {
  230.     //--- Remove the link ---
  231.     FW_ASSERT(fLink);
  232.     fLinkMgr->BreakDestinationLink(ev, fLink);
  233. }
  234.  
  235. //----------------------------------------------------------------------------------------
  236. // FW_CPrivCreateLinkCommand::RedoIt
  237. //----------------------------------------------------------------------------------------
  238. void FW_CPrivCreateLinkCommand::RedoIt(Environment* ev)
  239. {
  240.     //--- Restore the link ---
  241.     FW_ASSERT(fLink);
  242.     fLinkMgr->RestoreDestinationLink(ev, fLink);
  243. }
  244.  
  245.